#include "stm32f4xx_hal.h"
#include "stdio.h"

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "timers.h"

#include "DevicesQueue.h"
#include "DevicesKey.h"

#include "taskKey.h"
#include "taskSoftTimer.h"


/* 按键定时器句柄 */
static TimerHandle_t st_typeTimerKeyHandle;


static void vTimerCallbackKeyFunction( TimerHandle_t xTimer )
{
    (void)xTimer;

    /* 运行状态机，以检测是否有按键动作 */
    if(enumKeyStateMachine(&g_typeKeyData) != keyNormal)
    {
        /* 把按键值push到FIFO */
        enumQueuePushDatas(&g_TypeQueueKeyInput, &g_typeKeyData, sizeof(KeyTypeDef));

        /* 发送信号量 */
        xTaskNotifyGive(g_TaskKeyHand);
    }
}


void vTaskSoftTimerInit(void)
{
    /* 创建Key定时器，并启动 */
    st_typeTimerKeyHandle = xTimerCreate("Timer key", 50 / portTICK_RATE_MS, pdTRUE, 0, vTimerCallbackKeyFunction);
    xTimerStart(st_typeTimerKeyHandle, 0);
}
